//
//  DIYButton.m
//  01Eyes
//
//  Created by lanou on 15/11/5.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "DIYButton.h"

@implementation DIYButton



// 我们重写Button的frame方法 在里面修改视图
- (void)setFrame:(CGRect)frame
{
    // 因为我们的setFrame方法多次调用 如果不移除 会造成一个视图堆积的效果
    [_textLabel removeFromSuperview];
    [_iconImageView removeFromSuperview];
    [_selectIconImageView removeFromSuperview];
    
    CGFloat width = frame.size.height;
    
    // 创建我们的视图是一个正方形
    _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, width)];
    [self addSubview:_iconImageView];
    
    _selectIconImageView = [[UIImageView alloc] initWithFrame:self.iconImageView.frame];
    self.selectIconImageView.hidden = YES;
    [self addSubview:self.selectIconImageView];
    
    _textLabel = [[UILabel alloc]initWithFrame:CGRectMake(width + 10, 0, frame.size.width - width , frame.size.height)];
    [self addSubview:_textLabel];
    
    // 记得调用super setFrame方法
    [super setFrame:frame];
    
}

- (void)setSelected:(BOOL)selected
{
    if (selected) {
        _iconImageView.hidden = YES;
        _selectIconImageView.hidden = NO;
    }else{
        _iconImageView.hidden = NO;
        _selectIconImageView.hidden = YES;
    }
    
    [super setSelected:selected];
}




@end
